找传奇、传世资源到传世资源站!

winform 自定义进度条控件 源码 EasyProgressBar

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

winform 自定义进度条控件 源码 EasyProgressBar C#语言基础-第1张using System;using System.Text;using System.Drawing;using System.Drawing.Imaging;using System.Drawing.Drawing2D;using System.ComponentModel;using System.Windows.Forms;using System.Windows.Forms.Design;using System.Runtime.InteropServices;namespace EasyProgressBar{ partial class EasyProgressBar { [ToolboxItem(false)] partial class DropDownProgress : UserControl { #region API #region Symbolic Constants /// <summary> /// 当窗口显示区域的一部分显示内容或者全部变为“无效”,以致于必须“更新画面”时,将由这个消息通知程序。 /// </summary> private const int WM_PAINT = 0x000F; /// <summary> /// 是窗体客户区以外的重绘消息 /// </summary> private const int WM_NCPAINT = 0x0085; /// <summary> /// 消息是在指示HWND的整个背景窗体需要被擦除的时候才发送的。 /// </summary> private const int WM_ERASEBKGND = 0x0014; #endregion #region UnmanagedMethods /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图。 /// </summary> /// <param name="hwnd"></param> /// <returns></returns> [DllImport("user32", CharSet = CharSet.Auto)] internal static extern IntPtr GetDC( IntPtr hwnd); /// <summary> /// 函数释放设备上下文环境(DC)供其他应用程序使用。函数的效果与设备上下文环境类型有关。它只释放公用的和设备上下文环境,对于类或私有的则无效。 /// </summary> /// <param name="hwnd"></param> /// <param name="hdc"></param> /// <returns></returns> [DllImport("user32", CharSet = CharSet.Auto)] internal static extern int ReleaseDC( IntPtr hwnd, IntPtr hdc); #endregion #endregion #region Instance Members /// <summary> /// 用于显示 Windows 窗体,或者在设计模式下在属性网格控件的下拉区域中显示控件。 /// </summary> private IWindowsFormsEditorService editorService = null; private ColorizerProgress colorizer = null; #endregion #region Constructor public DropDownProgress() { InitializeComponent(); } public DropDownProgress(object value, IWindowsFormsEditorService editorService) : this() { this.editorService = editorService; if (value is ColorizerProgress) { this.colorizer = value as ColorizerProgress; } } #endregion #region Destructor ~DropDownProgress() { GC.SuppressFinalize(this); } #endregion #region Property public ColorizerProgress Colorizer { get { return colorizer = new ColorizerProgress((byte)redTrackBar.Value, (byte)greenTrackBar.Value, (byte)blueTrackBar.Value, (byte)alphaTrackBar.Value, colorizer.IsColorizerEnabled, colorizer.IsTransparencyEnabled); } } #endregion #region Override Methods /// <summary> /// Uygulamaya gelecek windows mesajları burda işlenir. /// </summary> /// <param name="m">Windows mesaj parametresi</param> protected override void WndProc(ref Message m) { // Kendi process işlemlerini yapsın. base.WndProc(ref m); // Daha sonra bizim metodumuzuda çağırsın. DrawBorder(ref m, this.Width, this.Height); } #endregion #region Helper Methods /// <summary> /// Kontrolümüz için kenarlık çiziyoruz. /// </summary> /// <param name="message">Kontrolümüzün Win32 mesaj işleme komutu</param> /// <param name="width">Kontrolümüzün genişlik değeri</param> /// <param name="height">Kontrolümüzün yükseklik değeri</param> private void DrawBorder(ref Message message, int width, int height) { if (message.Msg == WM_NCPAINT || message.Msg == WM_ERASEBKGND || message.Msg == WM_PAINT) { IntPtr hdc = GetDC(message.HWnd); if (hdc != IntPtr.Zero) { Graphics graphics = Graphics.FromHdc(hdc); Rectangle rectangle = new Rectangle(0, 0, width, height); ControlPaint.DrawBorder(graphics, rectangle, SystemColors.ActiveBorder, this.Padding.Left, ButtonBorderStyle.Solid, SystemColors.ActiveBorder, this.Padding.Top, ButtonBorderStyle.Solid, SystemColors.ActiveBorder, this.Padding.Right, ButtonBorderStyle.Solid, SystemColors.ActiveBorder, this.Padding.Bottom, ButtonBorderStyle.Solid); // Grafik nesnesinden kurtul. ReleaseDC(message.HWnd, hdc); } } } #endregion #region Event Handlers private void DropDownProgress_Load(object sender, EventArgs e) { redTrackBar.Value = colorizer.Red; greenTrackBar.Value = colorizer.Green; blueTrackBar.Value = colorizer.Blue; alphaTrackBar.Value = colorizer.Alpha; } private void closeDialogBtn_Click(object sender, EventArgs e) { editorService.CloseDropDown(); } private void TRACKBAR_VALUE_CHANGED(object sender, EventArgs e) { if (sender is TrackBar) { string result = null; TrackBar ctrl = (TrackBar)sender; if (ctrl.Value == 0) result = "Min"; else if (ctrl.Value == 255) result = "Max"; switch (ctrl.Name) { case "redTrackBar": label1.Text = String.Format("Red: {0}", result ?? ctrl.Value.ToString()); break; case "greenTrackBar": label2.Text = String.Format("Green: {0}", result ?? ctrl.Value.ToString()); break; case "blueTrackBar": label3.Text = String.Format("Blue: {0}", result ?? ctrl.Value.ToString()); break; default: label4.Text = String.Format("Alpha: {0}", result ?? ctrl.Value.ToString()); break; } } } #endregion } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复